<?php


namespace App\Http\Controllers\Web;


use App\Models\Page;
use App\Models\Topic;
use App\Repositories\NewRepository;
use App\Repositories\QuestionRepository;
use Illuminate\Http\Request;

class PageController extends BaseController
{



    public function index($uri,Request $request){


        $page = Page::where('uri','/'.trim($request->path(),'/'))->where('status',1)->first();
        if(!$page){
            return $this->topic($uri);
            //abort(404);
        }


        return view('web.page',compact('page'));
    }

    public function about(){


        $page = Page::where('uri','/about')->where('status',1)->first();

        $questions = app(QuestionRepository::class)->get();

        return view('web.about',compact('page','questions'));
    }

    public function process(){
        $page = Page::where('uri','/process')->where('status',1)->first();
        return view('web.process',compact('page'));
    }

    public function contact(){
        $page = Page::where('uri','/contact')->where('status',1)->first();
        return view('web.contact',compact('page'));
    }

    public function topic($title){
        $recommend = app(NewRepository::class)->recommend(4);
        $topic = Topic::where('title',$title)->where('status',1)->first();
        if(!$topic){
            abort(404);
        }
        $topics = Topic::where('status',1)->get();
        return view('web.topic',compact('recommend','topic','topics'));
    }


}
